import instance from "./utils/http";

export function getLoop(number){
    const url = `/api/weChat/applet/course/banner/list?number=${number}`;
    console.log('请求 URL:', url);
    return instance.get(url);
}

export function getList(type){
    let params = new URLSearchParams();
    params.append("type",type);
    params.append("pageNum","1");
    params.append("pageSize","5");
    const url = `/api/weChat/applet/course/list/type`;
    console.log('请求 URL:', url);
    return instance.post(url,params);
}

export function getDetail(){
    const url = `/api/weChat/applet/subject/list`;
    console.log('请求 URL:', url);
    return instance.post(url,{enable: 1});
}

export function getLink(){
    let params = new URLSearchParams();
    params.append("dictType", "blogroll");
    params.append("pageNum", "1");
    params.append("pageSize", "10");
    params.append("orderByColumn", "dictSort");
    params.append("isAsc", "asc");
    const url = `/api/system/dict/data/list/open`;
    console.log('请求 URL:', url);
    return instance.post(url, params);
}

export function getHot(data) {
    return instance.post(`/api/weChat/applet/article/list?pageNum=1&pageSize=5`,data);
}

// 新增获取课程详情的接口函数
export function getCourseDetail(courseId) {
    const url = `/api/pc/course/detail/${courseId}`;
    console.log('请求 URL:', url);
    return instance.get(url);
}

export function getSearch(){
    const url = `/api/weChat/applet/subject/list`;
    console.log('请求 URL:', url);
    return instance.post(url,{enable: 1});
}
export function getClassList(type, keyword, pagination) {
    // 构建查询参数
    const params = {
        keyword: keyword || '',
        type: type || '',
        subjectId: pagination.subjectId,
        courseType: pagination.courseType,
        pageNum: pagination.pageNum,
        pageSize: pagination.pageSize,
    };
    const url = `/api/pc/course/search/keyword`;
    console.log('请求 URL:', url);
    return instance.get(url, { params });
}

export function getLogin(username, password) {
   let params = new URLSearchParams();
    params.append("username", username);
    params.append("password", password);
    params.append("rememberMe", false);
    return instance.post("/api/pcUser/login", params);
}
export function getShop(){
    const url = `/api/weChat/applet/shoppingCart/my/list?status=`;
    console.log('请求 URL:', url);
    return instance.get(url);
}